package com.tanhua.model.vo;

import com.tanhua.model.mongo.Questionnaire;
import com.tanhua.model.mongo.Questions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionnaireVo implements Serializable {

    private String id;//主键id
    private String name;//问卷名称   --中级灵魂题
    private String cover;//封面
    private String level;//级别
    private Integer star;//星别（例如：2颗星，3颗星，5颗星）
    private List<QuestionsVo> questions;
    private Integer isLock = 0;//是否锁住（0解锁，1锁住）
    private String reportId;//最新报告id

    public static QuestionnaireVo init(Questionnaire questionnaire,List<Questions> questions){
        QuestionnaireVo vo = new QuestionnaireVo();
        BeanUtils.copyProperties(questionnaire,vo);
        List<QuestionsVo> questionsVos = questions.stream().map(c -> QuestionsVo.init(c)).collect(Collectors.toList());
        vo.setQuestions(questionsVos);
        vo.setId(String.valueOf(questionnaire.getId()));
        if (questionnaire.getReportId()==null){
            vo.setReportId(null);
        }else {
            vo.setReportId(String.valueOf(questionnaire.getReportId()));
        }

        return vo;
    }

}